package com.ctshk.sapp.certificate.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.certificate.dto.CertificateDTO;
import com.ctshk.rpc.certificate.dto.CertificateInfoDTO;
import com.ctshk.rpc.certificate.req.CertificatePageReq;
import com.ctshk.rpc.certificate.req.CertificateReq;
import com.ctshk.rpc.certificate.service.ICertificateBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 证件业务 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-19
 */
@Api(value = "证件业务",tags = "证件业务")
@RestController
@RequestMapping("/certificate-business")
public class CertificateBusinessController extends BaseController {

    @DubboReference
    private ICertificateBusinessService certificateBusinessService;

    @ApiOperation(value = "新增证件信息", notes = "新增证件信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增证件信息", operDesc = "新增证件信息")
    @PostMapping("/save")
    public Result saveCertificate(@RequestBody @Valid CertificateReq certificateReq) {
        TokenUser user = getCurrentUser(getRequest());
        return certificateBusinessService.saveCertificate(certificateReq, user);
    }

    @ApiOperation(value = "修改证件信息", notes = "修改证件信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改证件信息", operDesc = "修改证件信息")
    @PostMapping("/update")
    public Result updateCertificate(@RequestBody @Valid CertificateReq CertificateReq) {
         TokenUser user = getCurrentUser(getRequest());
        return certificateBusinessService.updateCertificate(CertificateReq, user);
    }

    @ApiOperation(value = "证件信息查询列表", notes = "证件信息查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "证件列表", operDesc = "证件列表")
    @PostMapping("/list")
    public Result<PageResponse<CertificateDTO>> queryCertificateList(@RequestBody CertificatePageReq certificateReq) {
        PageResponse<CertificateDTO> response = certificateBusinessService.queryList(certificateReq);
        return Result.success(response);
    }

    @ApiOperation(value = "查询证件信息详情", notes = "查询证件信息详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "编辑时查询证件信息详情", operDesc = "编辑时查询证件信息详情")
    @GetMapping(value = "/detail")
    public Result<CertificateInfoDTO> queryDetail(@RequestParam(value = "id") Long id) {
        return Result.success(certificateBusinessService.queryDetail(id));
    }
}
